<?php

class UrlParams
{
	/** @var int The zero-based index from the config's servers array */
	public $currentServer = 0; 
	/** @var string */
	public $currentDatabase;
	/** @var string */
	public $currentTable;
	/** @var string */
	public $mainPanel;
	
	public function __construct($auto = true)
	{
		if($auto)
		{
			foreach($_GET as $var => $val)
			{
				if(\property_exists($this, $var)) $this->$var = $val;
			}
		}
	}
	
	/**
	 * @return UrlParams
	 */
	public function link($props)
	{
		$obj = clone $this;
		foreach($props as $prop => $val)
		{
			if(\property_exists($obj, $prop)) $obj->$prop = $val;
		}
		return $obj;
	}
	
	public function __toString()
	{
		$arr = array();
		foreach($this as $prop => $val)
		{
			if($val !== null) $arr[$prop] = $val;
		}
		return \htmlspecialchars(\http_build_query($arr));
	}
}